<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
    <script src="/js/vue.min.js"></script>
    <script src="/js/axios.min.js"></script>
</head>

<body>

	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="#">首页</a></li>
    <li><a href="#">工具箱</a></li>
    </ul>
    </div>
    
    <div class="formbody" id="formbody">
    
    <div class="formtitle"><span>用户管理</span>
        <table style="margin-left: 80px">
            <tr>
                <td></td>
                <td v-for = "admin in adminList">
                    <input type="radio" name="adminId" v-model = "adminId" v-bind:value = "admin.aId" @Click = "getAdminRoles(admin.aId)"/>
                {{admin.aName}}</td>
            </tr>
        </table>
    </div>
    
    <div class="toolsli" >
    <ul class="toollist">
    <li v-for ="role in rolesList"><a href="#"><img src="images/i01.png" /></a>
        <h2><input type="checkbox" v-bind:value = "role.id" v-model = "roleIdList"/>{{role.rolename}}</h2></li>
    </ul>
    <span class="tooladd" @click = "updateUserRole()"><img src="images/add.png" title="修改" /></span>
    </div>
    </div>
</body>
<script>
    var vm = new Vue({
        el:"#formbody",
        data:{
            adminList:[],
            rolesList:[],
            adminId:"",
            roleIdList:[]
        },
        created(){
            this.loadAdmin();
            this.loadRoles();
        },
        methods:{
            loadAdmin:function () {
              axios.get("/adminAll").then(function (obj) {
                  if (obj.status==200){
                      //获取控制器的返回对象
                      var pageResult = obj.data;
                      if(pageResult.code==100){
                            alert(pageResult.msg);
                            location.href = "/login.html";
                            return;
                      }
                      vm.adminList = pageResult.object;
                  }
              }).catch(function (error) {
                    alert("出错了"+error);
              });
            },
            loadRoles:function () {
                axios.get("/rolesList").then(function (obj) {
                    if(obj.status==200){
                        var pageResult = obj.data;
                        if(pageResult.code==100){
                            alert(pageResult.msg);
                            location.href = "/login.html";
                            return;
                        }
                        vm.rolesList = pageResult.object;
                    }
                }).catch(function (error) {
                    alert("出错了"+error);
                })
            },
            getAdminRoles:function (aid) {
                axios.get("/AdminRoles",{params:{aId:aid}}).then(function (obj) {
                    if(obj.status==200){
                        var pageResult = obj.data;
                        if(pageResult.code==100){
                            alert(pageResult.msg);
                            return;
                        }
                        vm.roleIdList = pageResult.object;
                    }
                }).catch(function (error) {
                    alert("出错了"+error);
                });
            },
            updateUserRole:function () {
                if(confirm("确认修改角色权限吗?")){
                    var path = "/updateUserRole?adminId="+vm.adminId+"&roleIdList="+vm.roleIdList;
                    axios.put(path).then(function (obj) {
                        if (obj.status==200){
                            alert("修改成功");
                        }
                    }).catch(function (error) {
                        alert("出错了"+error);
                    });
                }
            }
        }
    });
</script>
</html>
